
const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack')
const path = require('path')

const debug = process.env.NODE_ENV !== 'production'
let cesiumSource = './node_modules/cesium/Source'
let localCesiumSource = './public/static/cesium'
let cesiumWorkers = '../Build/Cesium/Workers'
let localCesiumWorkers = './Workers'
let localSource = './public/static'
module.exports = {
  publicPath: './',
  configureWebpack: {
    output: {
      sourcePrefix: ' '
    },
    amd: {
      toUrlUndefined: true
    },
    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': path.resolve('src'),
        'cesium': path.resolve(__dirname, cesiumSource)
      }
    },
    plugins: [
      new CopyWebpackPlugin([{from: path.join(localCesiumSource, localCesiumWorkers), to: 'Workers'}]),
      new CopyWebpackPlugin([{from: path.join(localCesiumSource, 'Assets'), to: 'Assets'}]),
      new CopyWebpackPlugin([{from: path.join(localCesiumSource, 'Widgets'), to: 'Widgets'}]),
      new CopyWebpackPlugin([{from: path.join(localCesiumSource, 'ThirdParty/Workers'), to: 'ThirdParty/Workers'}]),
      new CopyWebpackPlugin([{from: path.join(localSource, 'model'), to: 'model3D'}]),
      new CopyWebpackPlugin([{from: path.join(localSource, 'SampleData'), to: 'SampleData'}]),
      new webpack.DefinePlugin({
        CESIUM_BASE_URL: JSON.stringify('./')
      })
    ],
    module: {
      unknownContextCritical: /^.\/.*$/,
      unknownContextCritical: false
    },
  },
    devServer: {
      disableHostCheck: true,
    publicPath:'/',
      proxy: {
        // '/geoserver/': {
        //   target: 'http://192.168.100.62:8080',
        //   changeOrigin: true,
        //   pathRewrite: {'^/geoserver': ''}
        // },
        '/tiles/': {
          target: 'http://ecn.t1.tiles.virtualearth.net',
          changeOrigin: true,
          pathRewrite: {'^/tiles': ''}
        },
        '/v1/assets/': {
          target: 'https://api.cesium.com/',
          changeOrigin: true,
          pathRewrite: {'^/v1/assets': ''}
        },

        // '/assets': {
        //   target: 'https://assets.cesium.com',
        //   changeOrigin: true,
        //   pathRewrite: {'^/assets': ''}
        // },
      },


  }
}
